package com.zjw.javase.reflect.proxy2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class BookFacadeProxy implements InvocationHandler {
	private Object target;
	
	public Object bind(Object target){
		this.target = target;
		
		return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		Object result = null;
		before();//代理业务
		result = method.invoke(target, args);//真正业务
		after();//代理业务
		
		return result;
	}
	
	private void before(){
		System.out.println("事前处理.....");
	}

	private void after(){
		System.out.println("事后处理.....");
	}
}




